<template>
  <basic-container>
    <avue-crud
      ref="crud"
      :option="option"
      :page.sync="page"
      :table-loading="listLoading"
      :data="list"
      @on-load="getList"
      @search-change="searchChange"
      @search-reset="searchReset"
      @refresh-change="refreshChange"
    >
      <template slot="menu" slot-scope="scope">
        <el-button type="text" size="mini" icon="el-icon-view" @click="handleDetail(scope.row)">详情</el-button>
        <el-button
          type="text"
          size="mini"
          icon="el-icon-edit"
          v-show="scope.row.reviewStatus !== '3'"
          @click="handleModify(scope.row)"
        >修改</el-button>
        <el-button
          type="text"
          size="mini"
          icon="el-icon-s-flag"
          v-show="scope.row.reviewStatus === '1'"
          @click="handleReview(scope.row)"
        >审核</el-button>
      </template>
      <template slot-scope="scope" slot="dealDateSearch">
        <el-date-picker
          v-model="dealDate"
          type="daterange"
          range-separator="至"
          value-format="yyyy-MM-dd"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
import { fetchList } from "../../api/bill/payable";
import { tableOption } from "../../const/crud/bill/payable";

export default {
  name: "payable",
  data() {
    return {
      option: tableOption,
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 20, // 每页显示多少条,
        isAsc: false // 是否倒序
      },
      list: [],
      listLoading: true,
      dealDate: []
    };
  },
  components: {},
  created() {
    this.getHeight();
  },
  methods: {
    getHeight() {
      let tableHeight = Math.max(window.innerHeight - 400, 300);
      this.option.maxHeight = tableHeight + "px";
    },
    getList(page, params={}) {
      this.listLoading = true;
      if (this.dealDate.length > 1) {
        params.startDate = this.dealDate[0];
        params.endDate = this.dealDate[1];
      }
      fetchList(
        Object.assign(
          {
            current: page.currentPage,
            size: page.pageSize
          },
          params
        )
      ).then(response => {
        this.list = response.data.data.records;
        this.page.total = response.data.data.total;
        this.listLoading = false;
      });
    },
    // 详情
    handleDetail(row) {
      let query = {
        res: {
          billSn: row.billSn
        }
      };
      this.$router.push({ path: "/payable/payableDetail", query: query });
    },
    handleModify: function(row) {
      let query = {
        res: {
          billSn: row.billSn
        }
      };
      this.$router.push({ path: "/payable/payableModify", query: query });
    },
    handleReview: function(row) {
      let query = {
        res: {
          billSn: row.billSn
        }
      };
      this.$router.push({ path: "/payable/payableReview", query: query });
    },
    /**
     * 搜索回调
     */
    searchChange(form, done) {
      this.getList(this.page, form);
      done();
    },
    /**
     * 刷新回调
     */
    refreshChange(info) {
      this.getList(this.page, this.filterForm(info.searchForm));
    },
    searchReset() {
      this.dealDate = [];
    }
  }
};
</script>

